Skip to content

feat: 581 - allow to implement different Asserts functions. implement some more assert utility functions#589

Closed
KammutierSpule wants to merge 6 commits intorokath:mainfrom
KammutierSpule:581
Closed

feat: 581 - allow to implement different Asserts functions. implement some more assert utility functions#589
KammutierSpule wants to merge 6 commits intorokath:mainfrom
KammutierSpule:581

Conversation

@KammutierSpule
Copy link
Contributor

Suggestion fix for #581

@github-actions github-actions bot added tests AnyChange go Pull requests that update go code C If any *.c or *.h file is changed in typical C locations. labels Dec 12, 2025
@rokath
Copy link
Owner

rokath commented Dec 12, 2025

Is this a typo? Did this PASS the ./testAll.sh script:

        break; case __LINE__: (void)Test_triceAssertOrReturnValue(0); //exp: "time:        default: ASSERT:flag not true!\n"
        break; case __LINE__: (void)Test_TriceAssertOrReturnValue(0); //exp: "time:    be16default: ASSERT:flag not true!\n"
        break; case __LINE__: (void)Test_TRiceAssertOrReturnValue(0); //exp: "time:feed3322default: ASSERT:flag not true!\n"

The (void) statements here?

@rokath
Copy link
Owner

rokath commented Dec 12, 2025

Still exists:

void triceAssertFail(int idN) {
	TRICE_ASSERT(id(idN));
}

void TriceAssertFail(int idN) {
	TRICE_ASSERT(Id(idN));
}

void TRiceAssertFail(int idN) {
	TRICE_ASSERT(ID(idN));
}

@KammutierSpule
Copy link
Contributor Author

Is this a typo? Did this PASS the ./testAll.sh script:

        break; case __LINE__: (void)Test_triceAssertOrReturnValue(0); //exp: "time:        default: ASSERT:flag not true!\n"
        break; case __LINE__: (void)Test_TriceAssertOrReturnValue(0); //exp: "time:    be16default: ASSERT:flag not true!\n"
        break; case __LINE__: (void)Test_TRiceAssertOrReturnValue(0); //exp: "time:feed3322default: ASSERT:flag not true!\n"

The (void) statements here?

Not a typo, it was to avoid warnings (not used return), but its ok I removed as there are no warnings on this test file.

tests are passing:

Translating all examples with TRICE_ON...pass
---
Script run 275 seconds.
✅ Test completed at: Fri Dec 12 11:52:45 AM WET 2025
🏁 Fri Dec 12 11:52:45 AM WET 2025 Done.

@KammutierSpule
Copy link
Contributor Author

Still exists:

void triceAssertFail(int idN) {
	TRICE_ASSERT(id(idN));
}

void TriceAssertFail(int idN) {
	TRICE_ASSERT(Id(idN));
}

void TRiceAssertFail(int idN) {
	TRICE_ASSERT(ID(idN));
}

I didn't understood it previously the issue, could you explain again?

@rokath
Copy link
Owner

rokath commented Dec 12, 2025

Not sure about this triceOff.h extension:

// ----- Arity detection helpers (C99) -----
#define _TRICE_PP_NARG_IMPL( \
          _1,_2,_3,_4,_5,_6,_7,_8,_9,_10, \
          _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
          N, ...) N
#define _TRICE_PP_NARG(...) \
        _TRICE_PP_NARG_IMPL(__VA_ARGS__, \
          20,19,18,17,16,15,14,13,12,11, \
          10,9,8,7,6,5,4,3,2,1,0)

#define _TRICE_PP_CAT(a,b) a##b
#define _TRICE_PP_OVERLOAD(name, count) _TRICE_PP_CAT(name, count)
#define _TRICE_PP_DISPATCH(name, ...) \
        _TRICE_PP_OVERLOAD(name, _TRICE_PP_NARG(__VA_ARGS__))(__VA_ARGS__)

// triceAssertOrReturn
#define triceAssertOrReturn2(msg, flag) do {if (!(flag)) {return;}} while(0)
#define TriceAssertOrReturn2(msg, flag) do {if (!(flag)) {return;}} while(0)
#define TRiceAssertOrReturn2(msg, flag) do {if (!(flag)) {return;}} while(0)
#define triceAssertOrReturn3(idN, msg, flag) do {if (!(flag)) {return;}} while(0)
#define TriceAssertOrReturn3(idN, msg, flag) do {if (!(flag)) {return;}} while(0)
#define TRiceAssertOrReturn3(idN, msg, flag) do {if (!(flag)) {return;}} while(0)

#define triceAssertOrReturn(...) _TRICE_PP_DISPATCH(triceAssertOrReturn, __VA_ARGS__)
#define TriceAssertOrReturn(...) _TRICE_PP_DISPATCH(TriceAssertOrReturn, __VA_ARGS__)
#define TRiceAssertOrReturn(...) _TRICE_PP_DISPATCH(TRiceAssertOrReturn, __VA_ARGS__)

// triceAssertOrReturnValue
#define triceAssertOrReturnValue3(msg, flag, value) do {if (!(flag)) {return (value);}} while(0)
#define TriceAssertOrReturnValue3(msg, flag, value) do {if (!(flag)) {return (value);}} while(0)
#define TRiceAssertOrReturnValue3(msg, flag, value) do {if (!(flag)) {return (value);}} while(0)
#define triceAssertOrReturnValue4(idN, msg, flag, value) do {if (!(flag)) {return (value);}} while(0)
#define TriceAssertOrReturnValue4(idN, msg, flag, value) do {if (!(flag)) {return (value);}} while(0)
#define TRiceAssertOrReturnValue4(idN, msg, flag, value) do {if (!(flag)) {return (value);}} while(0)

#define triceAssertOrReturnValue(...) _TRICE_PP_DISPATCH(triceAssertOrReturnValue, __VA_ARGS__)
#define TriceAssertOrReturnValue(...) _TRICE_PP_DISPATCH(TriceAssertOrReturnValue, __VA_ARGS__)
#define TRiceAssertOrReturnValue(...) _TRICE_PP_DISPATCH(TRiceAssertOrReturnValue, __VA_ARGS__)

Please add a few explaining words.

@KammutierSpule
Copy link
Contributor Author

Not sure about this triceOff.h extension:
Please add a few explaining words.

It looks it is the same purpose of what is on triceOn.h "The variadic macros"

I guess I should reuse it from triceOn.h.. maybe extracting those definitions and try to reuse it

@rokath
Copy link
Owner

rokath commented Dec 12, 2025

I run ./testAll.sh successfully on PR589 and I wonder the 3 (void) statements in triceCheck.c lines 154-156 are ok for the compiler. Sorry for closing this PR also. I really appreciate your work, Mario, and I hope you get not tired by creating a 3rd try.

  1. Correct (void)
  2. Remove triceAssertFail compleately
  3. Add documentation in place or remove the additional *triceOff.h` code, if not needed
  4. IMPORTANT: Please get an update from the rokath/trice main branch first, that we can avoid merging trouble.

@rokath rokath closed this Dec 12, 2025
@rokath
Copy link
Owner

rokath commented Dec 12, 2025

I didn't understood it previously the issue, could you explain again?

My comment in PR585:

triceAssertFail seems to be not right. What about changing definitions like this:
#define triceAssertOrReturn(idN, msg, flag) do {if (!(flag)) {trice(idN, msg); return;}} while(0)?

@rokath
Copy link
Owner

rokath commented Dec 12, 2025

Why not simply in `triceOff.h*:

#define triceAssertOrReturn(...) 
#define TriceAssertOrReturn(...)
#define TRiceAssertOrReturn(...) 

? Do not trust the AI too much! It is VERY helpful but NEEDS a critical review afterwards.

@KammutierSpule
Copy link
Contributor Author

Why not simply in `triceOff.h*:

#define triceAssertOrReturn(...) 
#define TriceAssertOrReturn(...)
#define TRiceAssertOrReturn(...) 

because of the "OrReturn"
in practice that #define needs to return from the function it is.. it is an helper function.
so: on debug it will log + return... OR on release it will return

@KammutierSpule
Copy link
Contributor Author

2. Remove triceAssertFail compleately

You suggestion to remove triceAssertFail and keep the triceAssertTrue ?
Not sure if this is on a previous release, but if it was, it will break previous compatibility

@rokath
Copy link
Owner

rokath commented Dec 12, 2025

We have

void triceAssertTrue(int idN, const char* msg, int flag); // ok
void triceAssertFalse(int idN, const char* msg, int flag); // ok
void triceAssert(int idN, const char* msg, int flag); // ok
void triceAssertFail(int idN); // WRONG!!!

@rokath
Copy link
Owner

rokath commented Dec 12, 2025

because of the "OrReturn"

I see...! Ok now I got the point. Probably a part of the AI conversation you had would be very helpful for other developers for understanding the additional triceOff.h code. Not everyone is a C macro expert. So please add a few explainig lines there too.

@rokath
Copy link
Owner

rokath commented Dec 12, 2025

I right now pushed an update into the main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AnyChange C If any *.c or *.h file is changed in typical C locations. go Pull requests that update go code tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants